<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!--
	파일명: updateCommonCode_p.jsp
	설명   : 공통코드 수정 
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>코드수정</title>
	<link rel="stylesheet" type="text/css" href="/inc/css/common.css" />
	<script type="text/javascript" src="/inc/css/common.js"></script>
	<script type="text/javascript">
	
		//
		function fnc_onload() {
			var msg = "<s:property value="msg" />"

			//alert(opener.document.getElementById("cur_page").value);

			if (msg == "OK") {
				alert("저장되었습니다.");
				window.close();
	   			//opener.location.reload();
	   			opener.call_dojo();
			}
			return false;
		}
		
		//검사
		function fnc_validate(f) {
			var flag = false;
			//하위코드화면일 경우
			if (f.group_code_nm == undefined) {
				
				if (f.cd.value == "") {
					alert("코드를 반드시 입력하시기 바랍니다11.");
					f.cd.focus();
					return flag;
				}
	
				//if(f.emp_nm.value.search(/\s/g)>-1){
				//       alert("공백문자는 허용하지 않습니다.");
				//       f.emp_nm.focus();
				 //      return false;
				//	}
				
				if (f.full_nm.value == "") {
					alert("코드명을 반드시 입력하시기 바랍니다.");
					f.full_nm.focus();
					return flag;
				}
				
				if (f.yn.value == "N" && f.use_yn.value == "Y") {
					alert("대표코드가 미사용으로 등록되어있어\r\n 미사용으로 등록만 가능합니다.");
					f.use_yn.value = "N";
					f.use_yn.focus();
					return false;				
				}
				
				return true;
			}
			
			//대표코드 화면일 경우 
			if (f.group_code_nm.value == ""){
				alert("대표코드명을 입력하시기 바랍니다.");
				f.group_code_nm.focus();
				return false;
			}

			if(f.group_code_nm.value.search(/\s/g)>-1){
                 alert("공백을 허용하지 않습니다.");
                 f.group_code_nm.focus();
                 return false;
			}
			if(f.etc.value.search(/\s/g)>-1){
                alert("공백을 허용하지 않습니다.");
                f.etc.focus();
                return false;
			}
			
			if(f.use_yn.value == "") {
				alert("사용여부를 선택하시기 바랍니다.");
				f.use_yn.focus();
				return false;
			}
			return true;
		}
		
		//저장버튼
		function updateCommonCode() {
			
			var f	=	form_pop;
			
			if(!fnc_validate(f)) {
				
				return false;
			}
		
			var cd 		= form_pop.cd.value;
			var use_yn	= form_pop.use_yn.value;
			
			if (cd == "0") {
				form_pop.action="attendUpdateCommonCode.action";
			}else {	
				form_pop.action="attendUpdateSubCommonCode.action";
			}
		}
		
		//하위코드 추가 버튼
		function addSubCommonCode(f) {
			var form	=	f;
	
			var group_cd 			= 		form.group_cd.value;
			var group_code_nm 		= 		form.group_code_nm.value;
			//group_code_nm  		= 		encodeURI(group_code_nm);
			var use_yn				=		form.use_yn.value;
			var yn					=		form.yn.value;
			
			if (yn == "N" || use_yn == "N") {
			
				alert("대표코드가 미사용으로 되어있습니다.\r\n\r\n사용여부를 \'Y\'저장하시고 \r\n하위코드를 추가 하시기 바랍니다.");
				return false;
			
			}
	
			if(group_code_nm == "") {
				alert("대표코드명을 입력하세요.");
				form.group_code_nm.focus();
				return false;
			}
			
			width 	= 550;
			height 	= 240;
			x = 350;
			y = 410;
			
			var uri	=	"attendAddSubCommonCode.action";
			
			//uri +=  "?group_cd="+group_cd+"&group_code_nm="+group_code_nm+"&checkedUseyn="+use_yn;
			
			var nm	=	"popup2";
			
			scrollOption = "no";
			var attr = "left="	+ x + ",top=" + y	+ ",width="	+ width + ",height=" + height	+ ",ScrollBars="+scrollOption+",status=yes,menubar=no";
			
			//window.open(uri ,	nm	,	attr);
			window.open("" ,	nm	,	attr);
			
			document.form_pop.target = nm;
			document.form_pop.action = uri;
			document.form_pop.submit();
			
			return false;
			
		}
	</script>
</head>
<body onload="fnc_onload()">
	
<s:form name="form_pop" theme="simple">
<div id="popup_550se_top" ></div>
<div id="popup_550se_bg">
	<table class="pop550se_Tbl">
	<s:iterator value="list" status="status" >
	<s:hidden id="yn" name="yn" />
	
	<s:if test='cd == "0"'>
	<s:hidden name="cd" id="cd" />
	<tr>
		<th>대표코드</th>
		<td><s:property value="group_cd" /><s:hidden name="group_cd" /></td>
		<th>대표코드명</th>
		<td>
			<input type="text" name="group_code_nm" value="<s:property value="group_code_nm" />" class="input_120se"></input>		
		</td>
	</tr>
	</s:if>
	<s:else>
	<tr>
		<th>대표코드</th>
		<td><s:property value="group_cd" />	<s:hidden name="group_cd" id="group_cd"/></td>
		<th>대표코드명</th>
		<td><s:property value="group_code_nm" /></td>
	</tr>
	<tr>
		<th>코드</th>
		<td>
			<input type="text" name="cd" value="<s:property value="cd" />" class="input_120se" maxlength="10"></input>
		</td>
		<th>코드명</th>
		<td>
			<input type="text" name="full_nm" value="<s:property value="full_nm" />" class="input_120se"></input>
			<s:hidden name="code" id="code" value="%{cd}" />		
		</td>
	</tr>
	</s:else>
	<tr>
		<th>사용여부</th>
		<td>
			<s:select name="use_yn" list="#{'Y':'Y','N':'N'}" cssClass="combobox120se"/>		
		</td>
		<th>비고</th>
		<td>
			<input type="text" name="etc" value="<s:property value="etc" />" class="input_120se"></input>		
		</td>
	</tr>
		<s:set name="sub_code" value="cd" />
	</s:iterator>
	</table>	
	<div id="popup_btn">
		<s:submit type="image" src="/images/btn_save.gif" onclick="return updateCommonCode()"/>
	</div>
</div>

<!---------------Bottom : STR----------->
<div id="popup_550se_bottom"><s:submit type="image" src="/images/pop_btn_close.gif" onclick="window.close(); return false;"/></div>
<!---------------Bottom : END----------->
</s:form>
</body>
</html>